var t = getApp();

Component({
    properties: {
        sid: {
            type: null
        }
    },
    data: {
        firstClass: 0,
        twoClass: 0,
        categoryInfo: [],
        onePage: 1,
        current_page_first: 1,
        last_page_first: 1,
        categoryInfo_two: [],
        twoPage: 1,
        current_page_two: 1,
        last_page_two: 1,
        keyInto: "",
        cat_level: "2"
    },
    lifetimes: {
        attached: function() {
            this.getClass();
        },
        moved: function() {},
        detached: function() {}
    },
    observers: {},
    methods: {
        init: function() {
            this.setData({
                onePage: 1,
                current_page_first: 1,
                last_page_first: 1,
                twoPage: 1,
                current_page_two: 1,
                last_page_two: 1,
                twoClass: 0,
                keyInto: ""
            });
        },
        toSearch: function(t) {
            var a = t.currentTarget.dataset.id;
            wx.navigateTo({
                url: "/packageA/member/supplier/SupplierSearch/SupplierSearch?id=" + this.data.sid + "&cid=" + a
            });
        },
        tapRightTwo: function(t) {
            this.setData({
                twoClass: t.currentTarget.dataset.id,
                keyInto: "thr_id".concat(t.currentTarget.dataset.kid)
            });
        },
        tapOneClass: function(t) {
            var a = t.currentTarget.dataset.ind;
            this.setData({
                firstClass: a
            }), this.init(), this.getClass();
        },
        getClass: function() {
            var a = this, e = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
            wx.showLoading({
                title: "加载中"
            });
            var s = t.getNetAddresss("plugin.supplier.frontend.shop.index.getParendCategory");
            t._getNetWork({
                url: s,
                data: {
                    sid: this.data.sid,
                    paginate: 100,
                    page: this.data.onePage
                },
                success: function(t) {
                    var s = t.data;
                    1 == s.result ? (a.setData({
                        cat_level: s.data.cat_level
                    }), e ? a.setData({
                        categoryInfo: a.data.categoryInfo.concat(s.data.data),
                        current_page_first: s.data.current_page,
                        last_page_first: s.data.last_page
                    }) : (a.setData({
                        categoryInfo: s.data.data,
                        current_page_first: s.data.current_page,
                        last_page_first: s.data.last_page
                    }), a.getClassTwo(a.data.categoryInfo[a.data.firstClass].id))) : (wx.showToast({
                        title: s.msg
                    }), wx.hideLoading({
                        success: function(t) {}
                    }));
                }
            });
        },
        getClassTwo: function(a) {
            var e = this, s = arguments.length > 1 && void 0 !== arguments[1] && arguments[1], o = arguments.length > 2 ? arguments[2] : void 0, r = t.getNetAddresss("plugin.supplier.frontend.shop.index.getChildrenCategory");
            t._getNetWork({
                url: r,
                data: {
                    sid: this.data.sid,
                    paginate: 15,
                    category_id: a,
                    page: this.data.twoPage
                },
                success: function(t) {
                    var r = t.data;
                    1 == r.result ? s ? (console.log("加载更多", r.data.category_2.data), e.getClassThr(a, r.data.category_2.data[e.data.twoClass].level, !0, o)) : "2" == e.data.cat_level ? (e.setData({
                        categoryInfo_two: r.data.category_2.data,
                        current_page_two: r.data.category_2.current_page,
                        last_page_two: r.data.category_2.last_page
                    }), wx.hideLoading({
                        success: function(t) {}
                    })) : e.getClassThr(a, r.data.category_2.data[e.data.twoClass].level) : (wx.showToast({
                        title: r.msg
                    }), wx.hideLoading({
                        success: function(t) {}
                    }));
                },
                fail: function(t) {
                    wx.hideLoading({
                        success: function(t) {}
                    });
                }
            });
        },
        getClassThr: function(a, e) {
            var s = this, o = arguments.length > 2 && void 0 !== arguments[2] && arguments[2], r = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : null;
            o && r && this.setData({
                twoPage: r
            });
            var i = t.getNetAddresss("plugin.supplier.frontend.shop.index.getChildrenCategory");
            t._getNetWork({
                url: i,
                data: {
                    sid: this.data.sid,
                    paginate: 15,
                    category_id: a,
                    page: this.data.twoPage,
                    level: e
                },
                success: function(t) {
                    var a = t.data;
                    if (wx.hideLoading({
                        success: function(t) {}
                    }), 1 == a.result) {
                        if (o) return console.log("加载更多取二级和三级", a), void s.setData({
                            categoryInfo_two: s.data.categoryInfo_two.concat(a.data.category_2.data),
                            current_page_two: a.data.category_2.current_page,
                            last_page_two: a.data.category_2.last_page
                        });
                        console.log("取三级category_2里面新增category_3", s.data.categoryInfo_two), s.setData({
                            categoryInfo_two: a.data.category_2.data,
                            current_page_two: a.data.category_2.current_page,
                            last_page_two: a.data.category_2.last_page
                        });
                    } else wx.hideLoading({
                        success: function(t) {}
                    }), wx.showToast({
                        title: a.msg
                    });
                },
                fail: function(t) {
                    wx.hideLoading({
                        success: function(t) {}
                    });
                }
            });
        },
        getMoreCategoryNew: function(t) {
            this.data.current_page_first >= this.data.last_page_first ? console.log("没有更多一级分类") : (this.setData({
                onePage: this.data.onePage + 1
            }), this.getClass(!0));
        },
        getMoreCategoryNew_two: function(t) {
            if (!(this.data.current_page_two >= this.data.last_page_two)) {
                var a = this.data.twoPage + 1;
                this.getClassTwo(this.data.categoryInfo[this.data.firstClass].id, !0, a);
            }
        }
    }
});